package com.example.demo.conflg;

import com.example.demo.common.TextGame;
import com.example.demo.common.TextMachine;
import com.example.demo.common.TextTatch;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor;

@Configuration
@EnableWebSocket
public class WebSocketConflg implements WebSocketConfigurer {
    @Autowired
    private TextTatch textTatch;

    @Autowired
    private TextGame textGame;

    @Autowired
    private TextMachine textMachine;
    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(textTatch,"/text")
                .addInterceptors(new HttpSessionHandshakeInterceptor());//拦截Http中的Session对象,复制到websocket中的Session中
        registry.addHandler(textGame,"/game")
                .addInterceptors(new HttpSessionHandshakeInterceptor());
        registry.addHandler(textMachine,"/machinegame")
                .addInterceptors(new HttpSessionHandshakeInterceptor());
    }
}
